package com.good.shopping.order.controller;

import com.good.shopping.order.entity.OrderEntity;
import com.good.shopping.order.entity.OrderReturnApplyEntity;
import com.good.shopping.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * RabbitMQ - 测试 发送消息
 * @author shengren.yan
 * @create 2022-03-13
 */

@RestController
public class RabbitController {

    // RabbitMQ - 发送消息
    @Autowired
    RabbitTemplate rabbitTemplate;

    //发送消息
    @GetMapping("/sendMq")
    public String sendMq(@RequestParam(value = "num",defaultValue = "10") Integer num){
        for (int i = 0; i < num; i++) {
            if (i % 2 == 0) {
                OrderReturnApplyEntity orderReturnApplyEntity = new OrderReturnApplyEntity();
                orderReturnApplyEntity.setId(1L);
                orderReturnApplyEntity.setCreateTime(new Date());
                orderReturnApplyEntity.setReturnName("哈哈哈");
                //配置MyRabbitConfig，让发送的对象类型的消息，可以是一个json
                // 参数 交换机 、路由件、对象、消息唯一id
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", orderReturnApplyEntity, new CorrelationData(UUID.randomUUID().toString()));
            } else {
                OrderEntity entity = new OrderEntity();
                entity.setOrderSn(UUID.randomUUID().toString());
                // rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", entity, new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "OK";
    }

    // OrderItemServiceImpl 接受消息

}
